using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Ajax_ret : MyPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            SqlCommand sp = new SqlCommand("cm_getText", conn);
                sp.CommandType = CommandType.StoredProcedure;
                sp.Parameters.AddWithValue("@eid", Request.QueryString["id"]);
            conn.Open();
            Response.Write((string)sp.ExecuteScalar());
        }
        else 
        {
            SqlCommand sp = new SqlCommand("cm_getEvents", conn);
                sp.CommandType = CommandType.StoredProcedure;
                sp.Parameters.AddWithValue("@StartFrom", "2000-01-01");
                sp.Parameters.AddWithValue("@Period", Request.QueryString["per"]);
                sp.Parameters.AddWithValue("@BUp", Request.QueryString["U"]);
                sp.Parameters.AddWithValue("@BDown", Request.QueryString["D"]);
                sp.Parameters.AddWithValue("@BLeft", Request.QueryString["L"]);
                sp.Parameters.AddWithValue("@BRight", Request.QueryString["R"]);
            conn.Open();
            SqlDataReader rdr = sp.ExecuteReader();
            Response.Write("[");
            while(rdr.Read())
            {
                Response.Write(String.Format("[{0},{1},{2},\"{3}\",\"{4}\",\"{5}\"],",
                rdr.GetInt32(0), rdr.GetDecimal(1), rdr.GetDecimal(2), rdr.GetString(3), rdr.GetString(4),
                rdr.GetDateTime(5).ToString("MMM dd")));
            }
            rdr.Close();
        }
        conn.Close();
    }
}
